home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / ODUtils / IText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  5.2 KB  |  175 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        IText.h
  3.  
  4.     Contains:    Routines for manipulating ITexts.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>      6/6/96    jpa        T10020: Added InitIText to initialize local
  13.                                     ODIText vars.
  14.          <3>     5/24/96    jpa        1.1MRD: pragma internal
  15.          <2>      5/1/96    JA        Force 68k alignment of TradITextData.
  16.                                     [1213332]
  17.  
  18.     To Do:
  19.     In Progress:
  20.         
  21. */
  22.  
  23. #ifndef _ITEXT_
  24. #define _ITEXT_
  25.  
  26. #ifndef _ODTYPES_
  27. #include "ODTypes.h"
  28. #endif
  29.  
  30.  
  31. typedef short ODScriptCode; 
  32. typedef short ODLangCode;
  33.  
  34.  
  35. #if PRAGMA_ALIGN_SUPPORTED
  36. #pragma options align=mac68k
  37. #endif
  38.  
  39. // ODTradIText: This is the format of the data stored in an IText whose
  40. // format is kODTradMacintosh.
  41.  
  42. struct ODTradITextDataHeader {
  43.     ODScriptCode theScriptCode;
  44.     ODLangCode     theLangCode;
  45. };
  46. typedef struct ODTradITextDataHeader ODTradITextDataHeader;
  47.  
  48. struct ODTradITextData {
  49.     ODScriptCode theScriptCode;
  50.     ODLangCode     theLangCode;
  51.     char         theText[1];        // Variable length array!
  52. };
  53. typedef struct ODTradITextData ODTradITextData;
  54.  
  55. #define kSizeOfODTradITextData    4
  56.  
  57. #if PRAGMA_ALIGN_SUPPORTED
  58. #pragma options align=reset
  59. #endif
  60.  
  61. #ifdef _OD_IMPL_SHARE_UTILS_
  62. #pragma import on
  63. #elif defined(PRAGMA_INTERNAL_SUPPORTED)
  64. #pragma internal on
  65. #endif
  66.  
  67.  
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71.  
  72.  
  73. ODIText*    CreateITextCString(ODScriptCode, ODLangCode, char* text);
  74. ODIText*    CreateITextPString(ODScriptCode, ODLangCode, StringPtr text);
  75. ODIText*    CreateITextClear(  ODScriptCode, ODLangCode, ODSize stringLength );
  76. ODIText*    CreateITextWLen(ODScriptCode, ODLangCode, ODUByte* text,
  77.                         ODSize textLength );
  78.     // For text that is neither a C string or a Pascal string.
  79.  
  80. ODIText*    InitIText( ODIText* );
  81.     // Used to setup ODIText structs not allocated from heap.
  82.     // Buffer will be set to NULL! Use SetBufferSize, SetStringLength, etc.
  83.  
  84. ODIText*    SetITextBufferSize( ODIText*, ODSize bufferSize, ODBoolean preserveContents );
  85.     // Low level operation to set byte-array buffer size directly.
  86.     // If input is NULL, will create & return a new ODIText.
  87.     
  88. ODIText*    CopyIText(ODIText* original);
  89.     // Allocates and returns an exact copy of the IText passed in.
  90. ODIText        CopyITextStruct(ODIText* original);
  91.  
  92. void        SetITextScriptCode(ODIText*, ODScriptCode);
  93. ODScriptCode GetITextScriptCode(ODIText*);
  94.  
  95. void        SetITextLangCode(ODIText*, ODLangCode);
  96. ODLangCode    GetITextLangCode(ODIText*);
  97.  
  98. ODIText*    SetITextStringLength( ODIText*, ODSize length, ODBoolean preserveText );
  99.     // If NULL is passed in, allocates & returns a new ODIText.
  100.  
  101. ODULong        GetITextStringLength(ODIText*);
  102. char*        GetITextPtr( ODIText* );
  103.     // Returns ptr to raw text without allocating any memory.
  104.  
  105. void        SetITextCString(ODIText*, char* text);
  106. void        SetITextPString(ODIText*, StringPtr text);
  107. void        SetITextText(ODIText*, ODUByte* text, ODSize textLength);
  108.  
  109. char*        GetITextCString(ODIText*, char *cstring);
  110. StringPtr    GetITextPString(ODIText*, Str255 pstring);
  111.     // If a string is passed in, it copies the text there and returns a ptr to it.
  112.     // If a NULL string is passed, it allocates a new string and returns it.
  113.  
  114.  
  115. void        DisposeIText(ODIText* iText);
  116. void        DisposeITextStruct(ODIText iText);
  117.  
  118. /* 
  119.     DisposeITextStruct is a macro instead of a function so it can take a
  120.     different parameter type than DisposeIText(), and still set the disposed
  121.     pointer field of the structure to null.
  122.     DisposeIText() must never be called on a IText structure;
  123.     DisposeIText() disposes the structure which is usually a disaster.
  124.  
  125.     See BArray.h for another example of this.
  126. */
  127.  
  128. #define    DisposeITextStruct(iText)        \
  129.     do{                                            \
  130.         if ((iText).text._buffer != kODNULL) {        \
  131.             ODDisposePtr((iText).text._buffer);    \
  132.             (iText).text._buffer = kODNULL;        \
  133.         }                                        \
  134.         (iText).text._length = 0;                    \
  135.         (iText).text._maximum = 0;                    \
  136.     }while(0)
  137.  
  138. #ifdef __cplusplus
  139.     } // closes extern "C" block
  140.     
  141.     // Overloaded variants for convenience:
  142.     inline ODIText*    CreateIText(ODScriptCode s, ODLangCode l, char* text)
  143.                         {return CreateITextCString(s,l,text);}
  144.     inline ODIText*    CreateIText(ODScriptCode s, ODLangCode l, StringPtr text)
  145.                         {return CreateITextPString(s,l,text);}
  146.     inline ODIText*    CreateIText(ODScriptCode s, ODLangCode l, ODSize stringLength )
  147.                         {return CreateITextClear(s,l,stringLength);}
  148.     inline ODIText*    CreateIText(ODSize textLength)
  149.                         {return SetITextStringLength(kODNULL,textLength,kODFalse);}
  150.     inline ODIText*    CreateIText(ODScriptCode scriptCode, ODLangCode langCode,
  151.                         ODUByte* text, ODSize textLength)
  152.                         {return CreateITextWLen(scriptCode, langCode, text, textLength );}
  153.  
  154.     inline void        SetITextString(ODIText* i, char* text)
  155.                         {SetITextCString(i,text);}
  156.     inline void        SetITextString(ODIText* i, StringPtr text)
  157.                         {SetITextPString(i,text);}
  158.     inline char*    GetITextString(ODIText* i, char* text)
  159.                         {return GetITextCString(i,text);}
  160.     inline StringPtr GetITextString(ODIText* i, StringPtr text)
  161.                         {return GetITextPString(i,text);}
  162.     inline char*    GetCStringFromIText(ODIText* iText)
  163.                         {return GetITextCString(iText,(char*)kODNULL);}
  164.     inline StringPtr GetPStringFromIText(ODIText* iText)
  165.                         {return GetITextPString(iText,(StringPtr)kODNULL);}
  166. #endif /*__cplusplus*/
  167.  
  168. #ifdef _OD_IMPL_SHARE_UTILS_
  169. #pragma import off
  170. #elif defined(PRAGMA_INTERNAL_SUPPORTED)
  171. #pragma internal reset
  172. #endif
  173.  
  174. #endif    /*_ITEXT_*/
  175.